<template>
	<view>
		<view class="p-30 bg-white border-radius2" v-for="(item, index) in lists" :key="index" @click="goDetail(item)">
			<view class="flex space-between ">
				<view class="flex items-center">
					<image src="../../static/images/message.png" mode="" style="width: 40rpx;height: 40rpx;border-radius: 50%;"></image>
					<view>
						<view class="font-no-wrap ml-20 font-26">{{item.title}}</view>
					</view>
				</view>
				<view class="font-20 font-grey">{{item.createTime}}</view>
			</view>
			<view>
				<view class="font-24 font-grey mt-20">{{item.message}}</view>
			</view>
		</view>
		
		<view class="text-center mt-200" v-if="lists.length === 0">暂无消息...</view>
	</view>
</template>

<script>
	import {list} from '../../api/message.js'
	export default {
		data() {
			return {
				user: null,
				type: 0,
				pageNo: 1,
				pageSize: 10,
				lists: []
			}
		},
		onShow() {
			this.getUserType()
			this.getList()
		},
		onReachBottom() {
			this.getList()
		},
		methods: {
			goDetail(item) {
				if (item.type === 0) {
					this.$goRoute.goUrl('/pages/lists/info?id='+item.info)
				}
				if (item.type === 1) {
					this.$goRoute.goUrl('/pages/company/details?id='+item.info)
				}
			},
			getList() {
				uni.showLoading({
					title: '加载中'
				})
				list({
					pageSize: this.pageSize,
					pageNo: this.pageNo,
				}).then(res => {
					if (this.pageNo === 1) {
						this.lists = res.result.records
					} else {
						this.lists.push(...res.result.records)
					}
					this.pageNo += 1
					uni.hideLoading()
				})
			},
			getUserType() {
				const user = uni.getStorageSync('userInfo')
				if (user) {
					this.user = user
					this.type = user.type
					if (user.type === 1) {
						uni.setTabBarItem({
						  index: 1,
						  text: '人才',
						  iconPath: 'static/images/t-2.png',
						  selectedIconPath: 'static/images/t-2-s.png'
						})
					}
				}
			},
		}
	}
</script>

<style lang="less">
	page {
		background-color: #f6f6f6;
	}
</style>
